#ifndef CG07_FPGRABBER
#define CG07_FPGRABBER

#include <boost/numeric/ublas/vector.hpp>
#include <vector>
#include <string>

/* class GrabberState  */
/* { */
/*  public: */
/*   boost::numeric::ublas::vector<float> pos; */
/*   boost::numeric::ublas::vector<float> ori; */
/*   boost::numeric::ublas::vector<float> up; */
/* }; */

class FPGrabber
{
private:
	boost::numeric::ublas::vector<float> pos;
	boost::numeric::ublas::vector<float> ori;
	boost::numeric::ublas::vector<float> up;

	boost::numeric::ublas::vector<float> rstPos;
	boost::numeric::ublas::vector<float> rstOri;
	boost::numeric::ublas::vector<float> rstUp;

	int lastX;
	int lastY;

	std::vector< boost::numeric::ublas::vector<float> > posStates;
	std::vector< boost::numeric::ublas::vector<float> > oriStates;
	std::vector< boost::numeric::ublas::vector<float> > upStates;

	void rotate(int key, float delta = 0.01);

	void forward();
	void backward();
	void left();
	void right();

	int keyDown[256];


public:
	FPGrabber(boost::numeric::ublas::vector<float> pos,
		boost::numeric::ublas::vector<float> ori,
		boost::numeric::ublas::vector<float> up);
	~FPGrabber();

	void handleKey(unsigned char key);
	void handleKeyUp(unsigned char key);
	void handleSpecialKey(int key, int mod);
	void handleMouse(int button, int state,int x, int y);
	void transform();
	void reset();
	int isKeyDown(unsigned char c);

	void write(std::string filename);
	void read(std::string filename);

	boost::numeric::ublas::vector<float> & FPGrabber::getPos();
	boost::numeric::ublas::vector<float> & FPGrabber::getOri();

	std::vector< boost::numeric::ublas::vector<float> > & getPosStates();
	std::vector< boost::numeric::ublas::vector<float> > & getOriStates();
	std::vector< boost::numeric::ublas::vector<float> > & getUpStates();
};


#endif
